<?php 
namespace Lib;
use \Lib\Record;


class Command
{
	
	public static function run($cli_argv=''){

		$default_tasks=C('DEFAULT_TASKS');

		//命令模式
		if (IS_CLI)
		{  	
			//去除***.php 参数
		    unset($cli_argv[0]);
		    $params=array();
		    foreach ($cli_argv as $key => &$arg) {
		    	$arg=str_replace(array('-','--'),'',$arg);
		    	$parse=explode('=',$arg);
		    	$parse[1] && $params[$parse[0]]=$parse[1];
		    }
		}else{
			$params=$_GET;
		}

		//加载到全局配置
		C('__PARAMS__',$params);

		$tasks=array_filter(explode(',',$params['task']));

		$tasks=empty($tasks)?array_merge($default_tasks,$tasks):$tasks;

		Record::add('ALL_TASK',$tasks);
		
		foreach ($tasks as $task) {
			
			$name=ucwords($task);
			$class='\\Task\\'.$name;

			if(class_exists($class)){

				$obj=new $class();
				$obj->run();

			}else{
				
				Record::add('TASK_NOT_FOUND',$class);
			}


		}

	}






}

?>